package com.wangsd.web.face.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangsd.web.face.entity.ReceiveRecord;
import com.wangsd.web.face.entity.Receiver;
import com.wangsd.web.face.entity.ServiceBusiness;
import com.wangsd.web.face.mapper.ReceiverMapper;
import com.wangsd.web.face.service.ReceiverService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author generator
 * @since 2019-09-17
 */
@Service
public class ReceiverServiceImpl extends ServiceImpl<ReceiverMapper, Receiver> implements ReceiverService {

    @Resource
    ReceiverMapper receiverMapper;

    @Override
    public IPage<Receiver> selectList(Integer pageNum, Integer pageSize, Receiver device) {
        Page<Receiver> page = new Page<>(pageNum, pageSize);
        IPage<Receiver> deviceIPage = receiverMapper.selectListXml(page, device);
        return deviceIPage;
    }

    @Override
    public void addOrUpdate(Receiver receiver) {
        if (receiver.getId() != null) {
            receiverMapper.updateById(receiver);
        } else {
            receiverMapper.insert(receiver);
        }
    }

    @Override
    public List<Receiver> selectAllByUserCode(String code) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (StringUtils.isNotBlank(code)) {
            queryWrapper.likeRight("code", code);
        }
        List<Receiver> list = receiverMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public List<Receiver> selectByMerchantId(Long merchantId) {
        return receiverMapper.selectByMerchantIdXml(merchantId);
    }

    @Override
    public List<ReceiveRecord> selectPaymentByOrderId(Long id) {
        return receiverMapper.selectPaymentByOrderIdXml(id);
    }
}
